package com.datastructure.test.exceltitle;

import java.util.HashSet;
import java.util.Set;

public class ExcelTitle {

    public static void main(String[] args) {
        ExcelTitle excelTitle = new ExcelTitle();
        String s = excelTitle.ExcelTitle(925);
        System.out.println(s);
    }

    public String ExcelTitle (int n) {
        // write code here
        int index=0;
        char[] chars = new char[26];
        for(char i = 'A';i<='Z';i++){
            chars[index]=i;
            index++;
        }
        StringBuilder result = new StringBuilder();
        while (n > 0) {
            n--;
            int tmp = n % 26;
            result.append(chars[tmp]);
            n = n / 26;
        }
        return result.reverse().toString();
    }

    public int getNumber (String S) {
        // write code here
        if(S == null  || S.length() == 0){
            return 0;
        }
        int result = 0;
        char[] chars = S.toCharArray();
        for (char c : chars) {
            result = result * 26 + (c - 'A' + 1);
        }
        return result;
    }

    public boolean isUnique (String str) {
        // write code here
        Set<Byte> set = new HashSet<>();
        byte[] bytes = str.getBytes();
        for (byte b : bytes) {
            if(set.contains(b)){
                return false;
            }
            set.add(b);
        }
        return true;
    }
}
